package o;

import android.app.Activity;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnDismissListener;
import android.text.InputFilter;
import android.text.InputFilter.LengthFilter;
import android.text.method.HideReturnsTransformationMethod;
import android.text.method.PasswordTransformationMethod;
import android.view.ActionMode;
import android.view.ActionMode.Callback;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout.LayoutParams;
import android.widget.TextView;
import java.security.NoSuchAlgorithmException;
import java.security.spec.InvalidKeySpecException;
import java.util.regex.Pattern;
import o.der.f;
import o.der.j;

public class ehd implements OnClickListener {
    private TextView ʻ;
    private long ʼ = 0;
    private d ʽ;
    private TextView ˊ;
    private EditText ˋ;
    private ehk ˎ;
    private FrameLayout ˏ;
    private EditText ॱ;
    private View ॱॱ;
    private int ᐝ = 0;

    public interface d {
        void ˎ();

        void ॱ();
    }

    class a implements cks {
        final /* synthetic */ ehd ॱ;

        private a(ehd o_ehd) {
            this.ॱ = o_ehd;
        }

        public void enableNetworking() {
            Logger.ˎ("PasswordDialogManager", "[global]  PasswordSettingClickListener performConfirm");
            if (this.ॱ.ˎ != null && !ActivityUtil.isAcitivtyNotValid(this.ॱ.ˎ.getActivity())) {
                String valueOf = String.valueOf(this.ॱ.ˋ.getText());
                String valueOf2 = String.valueOf(this.ॱ.ॱ.getText());
                if (dof.ˋ(valueOf) || dof.ˋ(valueOf2) || !this.ॱ.ˏ(valueOf) || !this.ॱ.ˏ(valueOf2)) {
                    this.ॱ.ʻ.setText(this.ॱ.ˎ.getActivity().getString(f.ᶫ));
                    Logger.ˎ("PasswordDialogManager", "[global]  PasswordSettingClickListener performConfirm password input error");
                } else if (valueOf.equals(valueOf2)) {
                    euf.ˎ().ˋ("first_visit_flag", false);
                    try {
                        valueOf2 = euz.ˏ();
                        euf.ˎ().ˋ("password", euz.ˋ(valueOf, valueOf2));
                        euf.ˎ().ˋ("secrect_iv", valueOf2);
                    } catch (NoSuchAlgorithmException e) {
                        Logger.ˋ("PasswordDialogManager", "NoSuchAlgorithmException");
                    } catch (InvalidKeySpecException e2) {
                        Logger.ˋ("PasswordDialogManager", "InvalidKeySpecException");
                    }
                    this.ॱ.ˎ.dismissAllowingStateLoss();
                    if (this.ॱ.ʽ != null) {
                        this.ॱ.ʽ.ॱ();
                    }
                } else {
                    this.ॱ.ʻ.setText(this.ॱ.ˎ.getActivity().getString(f.ʴ));
                    Logger.ˎ("PasswordDialogManager", "[global]  PasswordSettingClickListener performConfirm password input error");
                }
            }
        }

        public void upgrade() {
            Logger.ˎ("PasswordDialogManager", "[global]  PasswordSettingClickListener performCancel");
            if (this.ॱ.ʽ != null) {
                this.ॱ.ʽ.ˎ();
            }
        }

        public void ˋ() {
        }
    }

    class b implements cks {
        final /* synthetic */ ehd ˊ;

        private b(ehd o_ehd) {
            this.ˊ = o_ehd;
        }

        public void enableNetworking() {
            Logger.ˎ("PasswordDialogManager", "[global]  PasswordInputClickListener performConfirm()");
            Context ˋ = ContentManager.getInstant().getContext();
            long currentTimeMillis = System.currentTimeMillis() - this.ˊ.ʼ;
            if (this.ˊ.ʼ == 0 || currentTimeMillis >= 300000) {
                if (this.ˊ.ʼ != 0 && currentTimeMillis >= 300000) {
                    Logger.ˎ("PasswordDialogManager", "[global] " + " performConfirm() currTime - lastInputTime > FIVE_MIN lastInputTime=" + this.ˊ.ʼ + " timeBetween=" + currentTimeMillis);
                    this.ˊ.ᐝ = 0;
                    euf.ˎ().ˊ("retry_time", this.ˊ.ᐝ);
                    this.ˊ.ʼ = 0;
                    euf.ˎ().ˎ("last_input_ts", this.ˊ.ʼ);
                }
                this.ˊ.ᐝ = this.ˊ.ᐝ + 1;
                euf.ˎ().ˊ("retry_time", this.ˊ.ᐝ);
                Logger.ˎ("PasswordDialogManager", "[global]  performConfirm() retryTime=" + this.ˊ.ᐝ);
                if (this.ˊ.ᐝ > 5) {
                    Logger.ˎ("PasswordDialogManager", "[global]  performConfirm() retryTime > ERROR_TIMES_MAX ");
                    this.ˊ.ʻ.setText(ContentManager.getInstant().getContext().getResources().getQuantityString(j.ˊ, 5, new Object[]{Integer.valueOf(5), Integer.valueOf(5)}));
                    this.ˊ.ʼ = System.currentTimeMillis();
                    euf.ˎ().ˎ("last_input_ts", this.ˊ.ʼ);
                    return;
                }
                String valueOf = String.valueOf(this.ˊ.ˋ.getText());
                if (dof.ˋ(valueOf)) {
                    Logger.ˎ("PasswordDialogManager", "[global]  performConfirm() input password is blank. ");
                    this.ˊ.ʻ.setText(ˋ.getString(f.ᵎ));
                    return;
                }
                String ॱ = euf.ˎ().ॱ("password", "");
                if (dof.ˋ(ॱ)) {
                    Logger.ˎ("PasswordDialogManager", "[global]  performConfirm() pwdOriginal is blank. ");
                    this.ˊ.ʻ.setText(ˋ.getString(f.ᵎ));
                    return;
                }
                boolean ˊ;
                try {
                    ˊ = euz.ˊ(valueOf, ॱ, euf.ˎ().ॱ("secrect_iv", ""));
                } catch (NoSuchAlgorithmException e) {
                    Logger.ˋ("PasswordDialogManager", "NoSuchAlgorithmException");
                    ˊ = false;
                } catch (InvalidKeySpecException e2) {
                    Logger.ˋ("PasswordDialogManager", "InvalidKeySpecException");
                    ˊ = false;
                }
                if (ˊ) {
                    Logger.ˎ("PasswordDialogManager", "[global]  performConfirm() pwd is OK. ");
                    this.ˊ.ᐝ = 0;
                    this.ˊ.ʼ = 0;
                    euf.ˎ().ˊ("retry_time", this.ˊ.ᐝ);
                    euf.ˎ().ˎ("last_input_ts", this.ˊ.ʼ);
                    this.ˊ.ˎ.dismissAllowingStateLoss();
                    if (this.ˊ.ʽ != null) {
                        this.ˊ.ʽ.ॱ();
                        return;
                    }
                    return;
                }
                this.ˊ.ʻ.setText(ˋ.getString(f.ᵎ));
                return;
            }
            Logger.ˎ("PasswordDialogManager", "[global] " + " performConfirm() currTime - lastInputTime < FIVE_MIN lastInputTime=" + this.ˊ.ʼ + " timeBetween=" + currentTimeMillis);
            this.ˊ.ʻ.setText(ContentManager.getInstant().getContext().getResources().getQuantityString(j.ˊ, 5, new Object[]{Integer.valueOf(5), Integer.valueOf((int) Math.ceil(5.0d - ((((double) currentTimeMillis) * 1.0d) / 60000.0d)))}));
        }

        public void upgrade() {
            Logger.ˎ("PasswordDialogManager", "[global]  PasswordInputClickListener performCancel()");
            if (this.ˊ.ʽ != null) {
                this.ˊ.ʽ.ˎ();
            }
        }

        public void ˋ() {
        }
    }

    class c implements OnDismissListener {
        final /* synthetic */ ehd ˋ;

        private c(ehd o_ehd) {
            this.ˋ = o_ehd;
        }

        public void onDismiss(DialogInterface dialogInterface) {
            this.ˋ.ॱ();
        }
    }

    static class e implements Callback {
        private e() {
        }

        public boolean onPrepareActionMode(ActionMode actionMode, Menu menu) {
            return false;
        }

        public void onDestroyActionMode(ActionMode actionMode) {
        }

        public boolean onCreateActionMode(ActionMode actionMode, Menu menu) {
            return false;
        }

        public boolean onActionItemClicked(ActionMode actionMode, MenuItem menuItem) {
            return false;
        }
    }

    class g implements OnDismissListener {
        final /* synthetic */ ehd ॱ;

        private g(ehd o_ehd) {
            this.ॱ = o_ehd;
        }

        public void onDismiss(DialogInterface dialogInterface) {
            this.ॱ.ॱ();
        }
    }

    public ehd(Context context) {
        this.ॱॱ = LayoutInflater.from(context).inflate(o.der.g.ˏˎ, null);
        this.ˋ = (EditText) this.ॱॱ.findViewById(o.der.d.ᶫ);
        this.ॱ = (EditText) this.ॱॱ.findViewById(o.der.d.ㆍॱ);
        if (azc.ˎ().ॱ() > 17 && MinimumFactory.getBoolValue(ContentManager.getInstant().getContext())) {
            this.ˋ.setGravity(5);
            this.ॱ.setGravity(5);
        }
        this.ʻ = (TextView) this.ॱॱ.findViewById(o.der.d.ॱʾ);
        this.ˏ = (FrameLayout) this.ॱॱ.findViewById(o.der.d.ͺ);
        ImageView imageView = (ImageView) this.ॱॱ.findViewById(o.der.d.ˏॱ);
        if (azc.ˎ().ॱ() >= 17) {
            imageView.setVisibility(8);
        }
        this.ˊ = (TextView) this.ॱॱ.findViewById(o.der.d.ˋʻ);
        this.ˊ.setOnClickListener(this);
        this.ˊ.setTag(efx.PUSH_OFF);
        this.ʼ = euf.ˎ().ॱ("last_input_ts", 0);
        this.ᐝ = euf.ˎ().ॱ("retry_time", 0);
        Callback eVar = new e();
        this.ˋ.setCustomSelectionActionModeCallback(eVar);
        this.ॱ.setCustomSelectionActionModeCallback(eVar);
        this.ˋ.setFilters(new InputFilter[]{new LengthFilter(4)});
        this.ॱ.setFilters(new InputFilter[]{new LengthFilter(4)});
        this.ˋ.setInputType(18);
        this.ॱ.setInputType(18);
    }

    public void ˊ(Activity activity) {
        Logger.ˎ("PasswordDialogManager", "[global]  showPwdSettingDialog");
        this.ˎ = ehk.ˋ(activity, activity.getResources().getString(f.ᵢ), null);
        this.ˎ.ˊ(this.ॱॱ);
        this.ˎ.ॱ(-1, activity.getString(f.ॱʿ));
        this.ˎ.ˋ(activity, "content_restrict");
        this.ˎ.ˎ(new g());
        this.ˎ.ॱ(new a());
        this.ˎ.ˏ(new o.ehk.a(this) {
            final /* synthetic */ ehd ˎ;

            {
                this.ˎ = r1;
            }

            public void ˋ() {
                this.ˎ.ˋ();
            }
        });
        ˏ(activity);
    }

    private boolean ˏ(String str) {
        return Pattern.compile("^\\d{4}$").matcher(str).matches();
    }

    public void ˎ(Activity activity) {
        Logger.ˎ("PasswordDialogManager", "[global]  showInputPwdDialog");
        LayoutParams layoutParams = (LayoutParams) this.ˏ.getLayoutParams();
        layoutParams.bottomMargin = epv.ˋ(activity, 0);
        this.ˏ.setLayoutParams(layoutParams);
        this.ॱ.setVisibility(8);
        this.ʻ.setText(activity.getResources().getString(f.ߺ));
        this.ˎ = ehk.ˋ(activity, activity.getResources().getString(f.ᵔ), null);
        this.ˎ.ˊ(this.ॱॱ);
        this.ˎ.ॱ(-1, activity.getString(f.ॱʿ));
        this.ˎ.ˋ(activity, "content_restrict");
        this.ˎ.ˎ(new c());
        this.ˎ.ॱ(new b());
        this.ˎ.ˏ(new o.ehk.a(this) {
            final /* synthetic */ ehd ˏ;

            {
                this.ˏ = r1;
            }

            public void ˋ() {
                this.ˏ.ˋ();
            }
        });
        ˏ(activity);
    }

    private void ॱ() {
        if (this.ˎ != null) {
            try {
                this.ˎ.dismiss();
            } catch (IllegalStateException e) {
                Logger.e("PasswordDialogManager", "dialogcancel error: " + e.toString());
            }
            ˋ(this.ˎ.getActivity());
            this.ˎ = null;
        }
    }

    public void onClick(View view) {
        if (view.getId() == o.der.d.ˋʻ) {
            String str = (String) view.getTag();
            int selectionStart = this.ˋ.getSelectionStart();
            int selectionEnd = this.ˋ.getSelectionEnd();
            int selectionStart2 = this.ॱ.getSelectionStart();
            int selectionEnd2 = this.ॱ.getSelectionEnd();
            if (efx.PUSH_OFF.equals(str)) {
                this.ˊ.setBackgroundResource(o.der.e.ʼॱ);
                this.ˊ.setTag(efx.PUSH_ON);
                this.ˋ.setTransformationMethod(HideReturnsTransformationMethod.getInstance());
                this.ॱ.setTransformationMethod(HideReturnsTransformationMethod.getInstance());
            } else {
                this.ˊ.setBackgroundResource(o.der.e.ʾ);
                this.ˊ.setTag(efx.PUSH_OFF);
                this.ˋ.setTransformationMethod(PasswordTransformationMethod.getInstance());
                this.ॱ.setTransformationMethod(PasswordTransformationMethod.getInstance());
            }
            this.ˋ.setSelection(selectionStart, selectionEnd);
            this.ॱ.setSelection(selectionStart2, selectionEnd2);
        }
    }

    public void ˎ(d dVar) {
        this.ʽ = dVar;
    }

    private void ˋ() {
        if (this.ˋ != null && this.ˋ.getContext() != null) {
            this.ˋ.setFocusable(true);
            this.ˋ.setFocusableInTouchMode(true);
            this.ˋ.requestFocus();
            ((InputMethodManager) this.ˋ.getContext().getSystemService("input_method")).showSoftInput(this.ˋ, 0);
        }
    }

    private void ˏ(Activity activity) {
        if (activity != null && activity.getRequestedOrientation() != 1) {
            activity.setRequestedOrientation(1);
        }
    }

    private void ˋ(Activity activity) {
        if (activity != null && activity.getRequestedOrientation() != -1) {
            activity.setRequestedOrientation(-1);
        }
    }
}
